package cn.alex.sso.client.demo.controller;

import cn.alex.sso.client.demo.util.LscUtil;
import cn.dev33.satoken.sso.processor.SaSsoClientProcessor;
import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author Alex
 * @date 2025/1/9 下午1:57
 */
@RestController
public class LscController {

    @RequestMapping("/sso/*")
    public Object ssoRequest() {
        return SaSsoClientProcessor.instance.dister();
    }

    /**
     * 接收同步的数据
     */
    @PostMapping("/lc-sso/receiveSyncData")
    public String receiveUserData(@RequestBody Map<String, Object> data) {
        // 拿到同步的数据, 进行处理
        String d = LscUtil.decrypt(MapUtil.getStr(data, "data"));

        System.out.println(JSONUtil.formatJsonStr(d));

        return "接收成功";
    }

}
